import 'package:flutter/services.dart';

final basicMessageChannel = BasicMessageChannel("CHANNEL_BASIC_MESSAGE", JSONMessageCodec());

/// 事件处理
void dispatchMessage(Object? message) {
  print("dispatchMessage: $message");
}

/// 注册, 设置回调
void initBasicMessageChannel() {
  basicMessageChannel.setMessageHandler((Object? message) async {
    dispatchMessage(message);
    return message;
  });
}

/// 发送事件
void send(Object message) {
  basicMessageChannel.send(message).then((res) {
    print("message resp: $res");
  }).onError((error, trace) {
    print("message error: $error");
  });
}
